import random
import numpy as np
import scipy.sparse as ss
import numpy.random as npr
import struct
import ctypes

A = np.array(npr.random_sample(100));
A.reshape((10,10))
A = A + A.T
C = ss.coo_matrix(A)

bytes = ctypes.create_string_buffer(1244)
row_array = np.zeros(10)
row_array.fill(10)

base = 0
struct.pack_into('i', bytes, 0, 10)
base = 4
for idx, val in enumerate( row_array.flat) :
	struct.pack_into('i', bytes, base + idx * 4, val)
base = 44
for idx, tup in enumerate(zip(C.row, C.col, C.data)) :
	i = 0;
	struct.pack_into('i', bytes, base + (idx * 12) + (4*i), tup[0])
	i += 1;
	struct.pack_into('i', bytes, base + (idx * 12) + (4*i), tup[1])
	i += 1;
	struct.pack_into('f', bytes, base + (idx * 12) + (4*i), tup[2])

f = open('./coo_mat.bin', 'wb')
f.write(bytes)
f.close()







